﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CIT.WMS.query
{
    public partial class FrmQueryPartNumberInfo : Form
    {
        public FrmQueryPartNumberInfo()
        {
            InitializeComponent();
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txt_pn_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (txt_pn.Text.Length == 0)
                {
                    lab_msg.Text = "请输入物料编号.";
                    lab_msg.ForeColor = Color.Red;
                    txt_pn.SelectAll();
                    txt_pn.Focus();
                    return;
                }
                Utils.uContext.Accountk__BackingField = "mes40";
                DataTable dt = Utils.NMS.QueryDataTable(Utils.uContext, "select * from MdcDatMPN where newpn='" + txt_pn.Text + "'", new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dt.Rows.Count == 0)
                {
                    lab_msg.Text = "物料编号不存在.";
                    lab_msg.ForeColor = Color.Red;
                    txt_pn.SelectAll();
                    txt_pn.Focus();
                    return;
                }
                txt_locationid.Text = dt.Rows[0]["warehouselocation"].ToString();

                DataSet ds = Utils.NMS.QueryDataSet(Utils.uContext, "select count(*) from mdcdatvstorage where partnumber='" + txt_pn.Text + "' and (housecode ='027' or housecode='001') and qty=0 select sum(qty) from mdcdatvstorage where partnumber='" + txt_pn.Text + "' and housecode='007' group by partnumber select sum(qty) from mdcdatvstorage where partnumber='" + txt_pn.Text + "' and (housecode ='027' or housecode='001') group by partnumber", new CIT.WMS.MESWcf.CmdParameter[0]);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    txt_reelcount.Text = ds.Tables[0].Rows[0][0].ToString();
                }
                if (ds.Tables[1].Rows.Count > 0)
                {
                    txt_blockqty.Text = ds.Tables[1].Rows[0][0].ToString();
                }
                if (ds.Tables[2].Rows.Count > 0)
                {
                    txt_totalQty.Text = ds.Tables[2].Rows[0][0].ToString();
                }
                Utils.ERPType type = new Utils.ERPType();
                if (Utils.CheckConnectERP(out type))
                {
                    if (type == Utils.ERPType.YiFei)
                    {
                        Utils.uContext.Accountk__BackingField = "erpinfo";
                        dt = Utils.NMS.QueryDataTable(Utils.uContext, "select MB008 from INVMB_V where MB001='" + txt_pn.Text + "'", new CIT.WMS.MESWcf.CmdParameter[0]);
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            txt_locationid.Text += dt.Rows[i][0].ToString() + ",";
                        }
                    }
                }
                else
                {

                }
                lab_msg.Text = "查询成功.";
                lab_msg.ForeColor = Color.Lime;
                txt_pn.SelectAll();
                txt_pn.Focus();
            }
        }
    }
}